<template>
  <div id="userLayout" :class="['user-layout-wrapper']">
    <div class="container">
      <div class="top">
        <div class="header">
          <a href="/">
            <img src="@/assets/ofs.png" class="logo" alt="logo" />
          </a>
        </div>
        <div class="desc">
          履约系统
        </div>
      </div>
      <div class="main">
        <a-form class="user-layout-login" @keyup.enter.native="handleSubmit">
          <login-account ref="aLogin" @validateFail="validateFail" @success="requestSuccess" @fail="requestFailed"></login-account>

          <a-form-item>
            <a-checkbox @change="handleRememberMeChange" default-checked>自动登录</a-checkbox>
          </a-form-item>

          <a-form-item style="margin-top:24px">
            <a-button size="large"  type="primary"  htmlType="submit"  class="login-button"  :loading="loginBtn"  @click.stop.prevent="handleSubmit" :disabled="loginBtn">确定
            </a-button>
          </a-form-item>

        </a-form>
      </div>
      <div class="footer"></div>
    </div>
  </div>
</template>
<script setup>
import {ref} from "vue";
import LoginAccount from "@/views/login/loginAccount.vue";
import {notification} from "ant-design-vue";
import {timeFix} from "@utils/utils.js";
import {useRouter} from "vue-router";
const aLogin = ref()
const loginBtn = ref(false)
const rememberMe = ref(true)
const router = useRouter()
const handleSubmit =  () => {
  loginBtn.value = true;
  // this.$refs.alogin.handleLogin(this.rememberMe)
  aLogin.value.handleLogin(rememberMe.value)
}
const validateFail = () => {
  loginBtn.value = false;
}
// 登录后台成功
const requestSuccess = () => {
  loginSuccess()
}
//登录后台失败
const requestFailed = (err) => {
  let description = err
  notification.error({
    message: '登录失败',
    description:description,
    duration: 4,
  });
  console.log(description)
  //账户密码登录错误后更新验证码
  if(description.indexOf('密码错误')>0){
    aLogin.value.handleChangeCheckCode()
  }
  loginBtn.value = false;
}
const loginSuccess =  () => {
  // this.$router.push({ path: "/dashboard/analysis" })
  router.push({path:'/dashboard/analysis'})
  // .catch(()=>{
  //   console.log('登录跳转首页出错,这个错误从哪里来的')
  // })
  notification.success({
    message: '欢迎',
    description: `${timeFix()}，欢迎回来`,
  });
}
const handleRememberMeChange = (e) => {
  rememberMe.value = e.target.checked
}
</script>
<style lang="less" scoped>
.user-layout-login {
  label {
    font-size: 14px;
  }
  .getCaptcha {
    display: block;
    width: 100%;
    height: 40px;
  }

  .forge-password {
    font-size: 14px;
  }

  button.login-button {
    padding: 0 15px;
    font-size: 16px;
    height: 40px;
    width: 100%;
  }

  .user-login-other {
    text-align: left;
    margin-top: 24px;
    line-height: 22px;

    .item-icon {
      font-size: 24px;
      color: rgba(0,0,0,.2);
      margin-left: 16px;
      vertical-align: middle;
      cursor: pointer;
      transition: color .3s;

      &:hover {
        color: #1890ff;
      }
    }

  }
}
#userLayout.user-layout-wrapper {
  height: 100vh;

  &.mobile {
    .container {
      .main {
        max-width: 368px;
        width: 98%;
      }
    }
  }
.container {
  width: 100%;
  min-height: 100%;
  background: #f0f2f5 url(@/assets/background.svg) no-repeat 50%;
  background-size: 100%;
  padding: 110px 0 144px;
  position: relative;

  a {
    text-decoration: none;
  }

  .top {
    text-align: center;

    .header {
      height: 44px;
      line-height: 44px;

      .badge {
        position: absolute;
        display: inline-block;
        line-height: 1;
        vertical-align: middle;
        margin-left: -12px;
        margin-top: -10px;
        opacity: 0.8;
      }

      .logo {
        height: 60px;
        vertical-align: top;
        border-style: none;
      }

      .title {
        font-size: 33px;
        color: rgba(0, 0, 0, 0.85);
        font-family: 'Chinese Quote', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB',
        'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji',
        'Segoe UI Symbol';
        font-weight: 600;
        position: relative;
        top: 2px;
      }
    }

    .desc {
      font-size: 14px;
      color: rgba(0, 0, 0, 0.45);
      margin-top: 12px;
      margin-bottom: 40px;
    }
  }

  .main {
    min-width: 260px;
    width: 368px;
    margin: 0 auto;
  }

  .footer {
    position: absolute;
    width: 100%;
    bottom: 0;
    padding: 0 16px;
    margin: 48px 0 24px;
    text-align: center;

    .links {
      margin-bottom: 8px;
      font-size: 14px;

      a {
        color: rgba(0, 0, 0, 0.45);
        transition: all 0.3s;

        &:not(:last-child) {
          margin-right: 40px;
        }
      }
    }

    .copyright {
      color: rgba(0, 0, 0, 0.45);
      font-size: 14px;
    }
  }
}
}
</style>
<style>
.valid-error .ant-select-selection__placeholder{
  color: #f5222d;
}
</style>
